var str,
    parentHeight = null,
    childHeight = null,
    stepNum = 0,
    offsetY=50,
    moveTimer=null,
    ///////////////////////
    waitCountNum= 0,
    timeSpace=15,
    HZ=myexplorer(),
    staticTimer=null;
window.onload = function(){
    getRem(100,600);
};
window.onresize = function(){
        getRem(100,600);
        ajax();
};
function ajax(){
    $('.contentText ul').empty();
    $.ajax({
        type: "get",
        url: "preview/json/famous.json",
        dataType: "json",
        data: {},
        success: function (json) {
            $.each(json,function(i,e){
                str='<li class="animated">'+
                    '   <div class="famousText">'+ e.text+'</div>'+
                    '   <div class="famousAuthor">'+
                            '<span>'+e.author+'</span>' +
                        '</div>'+
                    '</li>';
                $('.contentText ul').append(str);
            });
            parentHeight = $('.contentText').height();
            childHeight = $('.contentText>ul').height();
            ////内容过多就执行滚动动效，内容少  就静止
            if (childHeight > parentHeight) {
                textMove();
            }else{
                $("li:eq(0)").addClass('lightSpeedIn').css({opacity:1}).siblings().css({opacity:0});///初始化设置第一条的动效
                /////给所有的数据绑定动画完成函数
                $('li').each(function(i,e){
                    $(e).on("webkitAnimationEnd mozAnimationEnd MSAnimationEnd animationend", function(event) {
                        event.stopPropagation();
                        $(e).next().addClass('lightSpeedIn').css({opacity:1}).siblings().removeClass('lightSpeedIn');
                    })
                });
                ///调用循环动效函数
                waitTime();
            }
        }
    });
}
///文字过长滚动函数
function textMove(){
    if(!!window.moveTimer)	cancelAnimationFrame(window.moveTimer);
    $('.contentText>ul').css({
        "top" : offsetY,
        "-webkit-transform" : "translate3d(0,-"+ stepNum +"px,0)",
        "transform" : "translate3d(0,-"+ stepNum +"px,0)"
    });
    stepNum += 0.2;
    if(stepNum >= (childHeight+offsetY)) {
        stepNum = 0;
    }
    moveTimer = requestAnimationFrame(textMove);
}
///内容过短 非滚动动效函数
function waitTime(){
    if(!!window.staticTimer)	cancelAnimationFrame(window.staticTimer);
    if(waitCountNum >= (timeSpace*HZ)){
        waitCountNum = 0;
        $('li').eq(0).addClass('lightSpeedIn').css({opacity:1}).siblings().removeClass('lightSpeedIn').css({opacity:0});
    }
    waitCountNum++;
    window.staticTimer = requestAnimationFrame(waitTime);
}

